<?php
//包含数据库配置文件
include '../../public/dbconfig.php';
//包含函数库文件
include '../../public/functions.php';
//调用函数 链接数据库
$link = con();

//接收需要删除的id
if(!empty($_POST)){
	$fid = implode(',',$_POST['fid']);
}else{
	$fid = $_GET['fid'];
}

//判断主贴下 是否有回帖
$sql = "select fid from htiezi,ftiezi where htiezi.fid=ftiezi.id and ftiezi.id in({$fid})";
//执行sql
$res = mysqli_query($link,$sql);
//判断执行结果
if($res && mysqli_num_rows($res)){
	//主贴下面有回帖
	//准备语句删除回帖
	$sql2 = "delete from htiezi where fid in({$fid})";
	//执行sql
	$res2 = mysqli_query($link, $sql2);
}
//准备删除语句
$sql3 = "delete from ftiezi where id in({$fid})";
//执行sql
$res3 = mysqli_query($link,$sql3);
//判断执行结果
if($res3){
	echo '<script>alert("删除成功");window.location.href="list.php";</script>';
}else{
	echo '<script>alert("删除失败");window.location.href="list.php";</script>';
}
//关闭数据库连接
mysqli_close($link);